package com.platform.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.platform.dao.BaseDAO;
import com.platform.model.User;

@Component(value = "userService")
@Transactional
public class UserServiceImpl implements UserService {
	@Autowired
	private BaseDAO<User, Long> userDAO;

	@Transactional(readOnly = true)
	public List<User> findAll() {
		return this.userDAO.findAll();
	}
	
	@Transactional(readOnly = true)
	public User find(final Long id) {
		return this.userDAO.findById(id);
	}

	@Transactional
	public void save(final User user) {
		this.userDAO.save(user);
	}

	@Transactional
	public void remove(final Long id) {
		final User user = this.find(id);
		
		if (user != null) {
			this.userDAO.delete(user);
		}
	}

	@Transactional
	public void remove(User user) {
		this.userDAO.delete(user);
    }
}